package com.xc.managersys.web.controller;

import com.xc.managersys.pojo.SysUser;
import com.xc.managersys.service.ISysUserService;
import com.xc.managersys.vo.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LoginController {

    @Autowired
    private ISysUserService sysUserService;

    @GetMapping("/login")
    public String toLogin(){
        return "login";
    }

    @ResponseBody
    @PostMapping("/login")
    public AjaxResult doLogin(String username, String password){

        SysUser sysUser = sysUserService.login(username, password);

        if (sysUser != null){
            return AjaxResult.success(sysUser);
        }

        return AjaxResult.error("用户名或密码错误");
    }
}
